package com.annotationAndReflection;

//测试类什么时候会初始化
public class TestClassInit {
    static {
        System.out.println("main类被加载");
    }

    public static void main(String[] args) throws ClassNotFoundException {
        //主动引用
        //new
//        Son son = new Son();
        //反射
        Class aClass = Class.forName("com.annotationAndReflection.Son");

        //被动引用
        //子类调用父类的静态方法，子类不会被加载
        System.out.println(Son.b);//main类被加载 父类被加载 2
        //数组
        Son[] sons = new Son[5];//main类被加载
        //常量
        System.out.println(Son.M);//main类被加载 1


    }

}

class Father{
    static int b = 2;
    static {
        System.out.println("父类被加载");
    }
}
class Son extends Father{
    static {
        System.out.println("子类被加载");
         m = 300;
    }
    static int m =100;
    static final int M = 1;//常量
}


    